﻿#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    string filename = "test.txt";

    // 写文件
    ofstream out(filename);
    out << "Line 1\nLine 2\nLine 3";
    out.close();

    // 读文件并统计行数
    ifstream in(filename);
    string line;
    int count = 0;
    while (getline(in, line)) {
        cout << "第 " << ++count << " 行: " << line << endl;
    }
    in.close();

    cout << "总共 " << count << " 行。" << endl;
    return 0;
}
